package marker.xml.metadata;

import java.io.File;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import marker.code.Constants;

public abstract class AbstractBean {

	public abstract String getName();

	public abstract String getModule();

	public abstract String getDesc();

	public abstract List<Property> getProperties();
	private Set<Property> properties2 ;

	public Set<Property> getAllProperties() {
		if(properties2==null){
			List<Property> properties = getProperties();
			properties2= new LinkedHashSet<Property>();
			for (Property property : properties) {
				properties2.add(property);
				if (property.getIfConditions() != null) {
					List<IfInfo> conditions = property.getIfConditions();
					for (IfInfo ifCondition : conditions) {
						if (ifCondition.getProperties() == null) {
							throw new RuntimeException("ifCondition properies is null!");
						}
						for(Property p:ifCondition.getProperties()){
							p.setInIf(true);
							properties2.add(p);
						}
					}
				}
			}
		}
		return properties2;
	}

	public abstract String getClassName();

	public abstract String getSimpleClassName();

	public String getPackage() {
		return Constants.MsgPackage + "." + getModule();
	}

	public String getAsFilePath() {
		String path = Constants.CodePath + File.separatorChar + "client" +
				File.separatorChar + (getClassName().replaceAll("\\.", "\\\\")) + ".as";
		return path;
	}

	public String getJavaFilePath() {
		String path = Constants.CodePath + File.separatorChar + "server" +
				File.separatorChar + getClassName().replaceAll("\\.", "\\\\") + ".java";
		return path;
	}

}
